﻿Imports System.Object
Imports VSModel
Imports Cls_Common
Partial Class FrontEnd_Control_Store_RightRaoVat
    Inherits System.Web.UI.UserControl
    Public strSalonURL As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then

            If Not Page.RouteData.Values("Id") Is Nothing Then


                BindToGrid(Page.RouteData.Values("Id"))
            End If

        End If

    End Sub
    Private Sub BindToGrid(ByVal _StoreId As Integer)
        Using Data As New VSEntities

            Dim p As List(Of RaoVat)
            Dim _Store = (From q In Data.Stores Where q.StoreId = _StoreId Select q).FirstOrDefault
            strSalonURL = _Store.QueryString & "-" & _Store.StoreId.ToString & "/"
            p = (From q In Data.RaoVats Where q.UserId = _Store.UserId And q.StatusId = 3 _
                                                And q.PublishedDate <= Now() _
                                            Order By q.Modified Descending, q.Created Descending Select q).Take(20).ToList

            With rptProduct
                .DataSource = p
                .DataBind()
            End With

        End Using
    End Sub

    Protected Sub rtpProduct_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptProduct.ItemDataBound
        Dim row As VSModel.RaoVat = CType(e.Item.DataItem, VSModel.RaoVat)

        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)



 
        hplTitle.Text = row.Title
        hplTitle.NavigateUrl = MainDomain & strSalonURL & row.QueryString & "-" & row.RaovatId.ToString & ".html"
        Dim ltrDescription As Literal = CType(e.Item.FindControl("ltrDescription"), Literal)
        ltrDescription.Text = CropText(row.Description, 100, "...")
        'Dim ltrUSD As Literal = CType(e.Item.FindControl("ltrUSD"), Literal)
        'ltrUSD.Text = "~ " & CType((row.OriginalPrice * 1000000) / TyGia, Double).ToString("#,##0") & " USD"




        Dim imgProduct As Image = CType(e.Item.FindControl("imgProduct"), Image)


        imgProduct.ImageUrl = CookedImageURL("84-84", row.ImagePreview.ToString)
        imgProduct.AlternateText = row.Title

        Dim ltrPrice As Label = CType(e.Item.FindControl("ltrPrice"), Label)
        ltrPrice.Text = IIf(row.OriginalPrice = 0, "Call", FormatCurrencyOto(row.OriginalPrice.ToString))

        'Dim ltrLienHe As Literal = CType(e.Item.FindControl("ltrLienHe"), Literal)

        'Dim ltrTelephone As Literal = CType(e.Item.FindControl("ltrTelephone"), Literal)
        'ltrLienHe.Text = row.HoTen & Environment.NewLine & row.DiaChi
        'ltrTelephone.Text = row.Phone

        'If Not row.PhoneOther Is Nothing AndAlso row.PhoneOther <> "" Then
        '    ltrTelephone.Text = ltrTelephone.Text & " - " & row.PhoneOther
        'End If

        'Dim ltrMaTin As Literal = CType(e.Item.FindControl("ltrMaTin"), Literal)
        'ltrMaTin.Text = "Mã: " & row.Code
        'Dim ltrTinhThanh As Literal = CType(e.Item.FindControl("ltrTinhThanh"), Literal)
        'If Not IsNothing(row.TinhTP) Then
        '    ltrTinhThanh.Text = GetTinhThanhPho(row.TinhTP)
        'End If



    End Sub
    Private Function getTinhTrangXe(ByVal _RaoVatId As Integer) As String
        Using _data As New VSEntities
            Dim p = (From q In _data.ThongSoCoBans Where q.RaoVatId = _RaoVatId Select q.TinhTrang, q.NamSanXuat).FirstOrDefault
            If Not p Is Nothing AndAlso p.TinhTrang = 1 Then
                Return " Xe mới " & p.NamSanXuat.ToString
            Else
                Return " Xe cũ " & p.NamSanXuat.ToString
            End If
        End Using

    End Function

    Private Function GetTinhThanhPho(ByVal _TinhThanhId As Integer) As String
        Using _data As New VSEntities
            Dim p = (From q In _data.DonViHanhChinhs Where q.Id = _TinhThanhId Select q.Title).FirstOrDefault
            If Not p Is Nothing Then
                Return p
            End If

        End Using
        Return ""
    End Function

End Class
